package test;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		System.out.println("add");
		//再加一行
		System.out.println("试试咯");
		
		//再加一行
		//再加一行
		//再加一行
		Scanner sc = new Scanner(System.in);
		String nn = sc.nextLine();
		int n = Integer.parseInt(nn);
		String[] s = new String[n];
		String[] b = new String[n];

		for (int i = 0; i < n; i++) {
			s[i] = sc.nextLine();
			String p = i + "";
			b[i] = "0";
			b[i] = b[i].concat(s[i].substring(6, 14));
			b[i] = b[i].concat(p);
		}
		Arrays.sort(b);
		//int count = 0;
		String q = sc.nextLine();
		while (q.equals("sort1") || q.equals("sort2")) {
			for (int i = 0; i < n; i++) {
				String cc = b[i].substring(b[i].length() - 1, b[i].length());
				int c = Integer.parseInt(cc);
				if (q.equals("sort1")) {
					System.out.print(s[c].substring(6, 10) + '-');
					System.out.print(s[c].substring(10, 12) + '-');
					System.out.println(s[c].substring(12, 14));
				} else if (q.equals("sort2")) {
					System.out.println(s[c]);
				}
			}
			q = sc.nextLine();
		}
		System.out.println("exit");
	}
}

